<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="http://mat1.gtimg.com/libs/jquery2/2.2.0/jquery.js"></script>
</head>
<body>
{#<form action="" method="post">#}
{#    {% csrf_token %}#}
帐号: <input type="text" name="uname" id="uname"><span id="span"></span>
密码: <input type="text" name="pwd" id="pwd"><span id="span"></span>
<button onclick="f()">登录</button>
{#</form>#}
<script>
    function f() {
        var name = $('#uname').val()
        var pwd = $('#pwd').val()
        if (name.length === 0) {
            $("#span").html('用户名不能为空')
            $("#span").css('color', 'red')
        }
        if (pwd.length === 0) {
            $("#span").html('密码不能为空')
            $("#span").css('color', 'red')
        }
        $.ajax({
            type:'POST',
            url:'{% url 'loginoy' %}',
            data:{'name':name,'pwd':pwd},
            success:function (result) {
                if (result.flag===1){
                    location.href = '{% url 'all' %}'
                }
                else {
                    alert('帐号密码错误')
                }
            },
            error:function () {
                alert('服务器出错啦')
            }
        })
    }
</script>
</body>
</html>